import init from './lib/init.js'
import fs from 'fs';
import path from 'path';

const __dirname = path.resolve();
const sourceFilePath = path.join(__dirname, 'plugins', 'MEMZ-Plugin', 'config', 'default_config', 'all.config.yaml');
const targetFilePath = path.join(__dirname, 'plugins', 'MEMZ-Plugin', 'config', 'all.config.yaml');
if (!fs.existsSync(targetFilePath)) {
    fs.renameSync(sourceFilePath, targetFilePath);
    console.log(`成功将文件移动到目标位置: ${targetFilePath}`);
} else {
    console.log(`目标文件已存在，无需移动。`);
}
const sourceUninstallFilePath = path.join(__dirname, 'plugins', 'MEMZ-Plugin', 'component', 'UninstallMEMZ.js');
const targetUninstallFilePath = path.join(__dirname, 'plugins', 'example', 'UninstallMEMZ.js');
if (!fs.existsSync(targetUninstallFilePath)) {
    fs.renameSync(sourceUninstallFilePath, targetUninstallFilePath);
} else { console.log(`MEMZ检查文件成功`); }
(async () => {
  let CM;
  let lj;
  const libPath = path.resolve(__dirname, './lib/common/CM.js');
  const pluginPath = path.resolve(__dirname, './plugins/MEMZ-Plugin/lib/common/CM.js');
  if (fs.existsSync(libPath)) {
    lj = 'file://' + libPath;
  } else {
    lj = 'file://' + pluginPath;
  }
  try {
    CM = await import(lj);
    if (!global.cm){
    logger.info('[MEMZ-Plugin]CM已存在')
    }else{
        global.cm = CM.default;
        logger.info('[MEMZ-Plugin]CM载入完成')
    }
  } catch (error) {
    logger.error('[MEMZ-Plugin]载入CM.js失败', error);
  }
})();
init.init()

if (false) {
  logger.info(logger.red("                        _oo0oo_"));
  logger.info(logger.red("                       o8888888o"));
  logger.info(logger.red("                       88' . '88"));
  logger.info(logger.red("                       (| -_- |)"));
  logger.info(logger.red("                       0\\  =  /0"));
  logger.info(logger.red("                     ___/`---'\\___"));
  logger.info(logger.red("                   .' \\\\|     |// '."));
  logger.info(logger.red("                  / \\\\|||  :  |||// \\ "));
  logger.info(logger.red("                 / _||||| -:- |||||- \\ "));
  logger.info(logger.red("                |   | \\\\\\  - /// |   | "));
  logger.info(logger.red("                | \\_|  ''\---/''  |_/ | "));
  logger.info(logger.red("                \\  .-\__  '-'  ___/-. / "));
  logger.info(logger.red("              ___'. .'  /--.--\\  `. .'___ "));
  logger.info(logger.red("           .'' '<  `.___\\_<|>_/___.' >' ''. "));
  logger.info(logger.red("          | | :  `- \\`.;`\\ _ /`;.`/ - ` : | | "));
  logger.info(logger.red("          \\  \\ `_.   \\_ __\\ /__ _/   .-` /  / "));
  logger.info(logger.red("      =====`-.____`.___ \\_____/___.-`___.-'===== "));
  logger.info(logger.red("                        `=---='"));
  logger.info(logger.red(""));
  logger.info(logger.red("      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"));
  logger.info(logger.red("            佛祖保佑     永不宕机     永无BUG"));
  logger.info(logger.red("                  memz-plugin 启动！              "));
  logger.info(logger.red(""));
  logger.info(logger.red(" /$$      /$$ /$$$$$$$$ /$$      /$$ /$$$$$$$$"));
  logger.info(logger.red("| $$$    /$$$| $$_____/| $$$    /$$$|_____ $$ "));
  logger.info(logger.red("| $$$$  /$$$$| $$      | $$$$  /$$$$     /$$/ "));
  logger.info(logger.red("| $$ $$/$$ $$| $$$$$   | $$ $$/$$ $$    /$$/  "));
  logger.info(logger.red("| $$  $$$| $$| $$__/   | $$  $$$| $$   /$$/   "));
  logger.info(logger.red("| $$\\   | $$| $$      | $$\\  $ |$$  /$$/    "));
  logger.info(logger.red("| $$ \\/ | $$  $$$$$$$$| $$ \\/  | $$ /$$$$$$$$"));
  logger.info(logger.red("|__/     |__/|________/|__/      |__/|________/"));
}
console.log("欢迎使用MEMZ-Plugin")
